Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(upgrade): need to call markForCheck on child changeDetectorRef #22209

Closed
wants to merge 1 commit into from

Conversation

smdunn
Copy link

@smdunn smdunn commented Feb 13, 2018

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] angular.io application / infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

I found a bug within matCheckbox. I added a disabled class to the checkbox based on a method call. When disabled, the checkbox had class disabled and therefore had grey css etc, but if it was still clicked on, it had a click event which added a disabled class to the input within the checkbox. When the disabled class was removed from the outer matCheckbox, the disabled class remained on the input, so even though the checkbox appeared not to be disabled, it couldn't accept any more input.

Issue Number: 9763

What is the new behavior?

Clicking on a disabled checkbox should not change it in any way.

Does this PR introduce a breaking change?

[ ] Yes
[x ] No

Other information

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address on your commit. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot. The email used to register you as an authorized contributor must be the email used for the Git commit.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@smdunn
Copy link
Author

smdunn commented Feb 13, 2018

I signed it!

@@ -139,6 +141,7 @@ export class DowngradeComponentAdapter {
(<OnChanges>this.component).ngOnChanges(inputChanges !);
}

this.childComponentChangeDetector.markForCheck();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the existing change detector: this.changeDetector.markForCheck();
And I suppose you need a unit test for this change as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values of this.componentRef.injector.get(ChangeDetectorRef) and this.componentRef.changeDetectorRef are not the same, and calling markForCheck on the this.changeDetector does not fix my bug.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, oddly this.changeDetector is not the wrapped component's actual change detector. Calling markForCheck on it has no effect (at least as far as this issue is concerned).

@mhevery mhevery added the area: core Issues related to the framework runtime label Feb 14, 2018
@rkirov rkirov requested a review from gkalpak February 15, 2018 19:35
@rkirov
Copy link
Contributor

rkirov commented Feb 15, 2018

Looks good given my limited understanding of ngupgrade internals. Would probably need a test too (do you need help with that?).

@gkalpak can you take an expert look at this?

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable, but we do need some tests 😁
(LMK if you need help with that.)

@@ -60,6 +61,7 @@ export class DowngradeComponentAdapter {

this.componentRef =
this.componentFactory.create(childInjector, projectableNodes, this.element[0]);
this.childComponentChangeDetector = this.componentRef.injector.get(ChangeDetectorRef);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really the child's ChangeDetector? I would actually think it is the component's ChangeDetector (or rather the ChangeDetector of the View within which this component resides). But I could be wrong 😁

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the same instance that is injected into the wrapped component. So whatever that is.

@gkalpak
Copy link
Member

gkalpak commented Feb 15, 2018

BTW, I suspect this is related to #14286 (in the sense that the underlying issue is the same/similar). In which case, this comment (ignore the associated commit) would explain what is going on.

I am not sure I understand the usecase, so having a failing testcase or a demo would help.
(If you want to put together a live demo, you can use one of my stackblitz templates: ngUpgrade or ngUpgradeLite)

@kseamon
Copy link
Contributor

kseamon commented Feb 15, 2018

The specific issue we encountered was with the [disabled] attribute of MatCheckbox not updating properly. One possibly confounding factor is that it is a property setter that sets the value of _disabled which is what the component actually uses. But that said, when we tried to reproduce the issue in a pure Angular (5) setting, it worked fine.

@gkalpak
Copy link
Member

gkalpak commented Feb 16, 2018

Are you using ngUpgradeLite or plain ol' ngUpgrade?
Any chance you could share a minimal reproduction (e.g. as a repo or on stackblitz (see my previous comment))?

@smdunn
Copy link
Author

smdunn commented Feb 22, 2018

I added a test case that fails when the change I added is removed.

@kseamon
Copy link
Contributor

kseamon commented Feb 23, 2018

Take a look at the unit test for a repro. I think this issues applies to both versions of ngupgrade, but we were using full when we encountered it.

@gkalpak gkalpak changed the title fix(matcheckbox): need to call markForCheck on child changeDetectorRef fix(upgrade): need to call markForCheck on child changeDetectorRef Mar 1, 2018
@gkalpak gkalpak added type: bug/fix comp: upgrade/static target: patch This PR is targeted for the next patch release action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 1, 2018
Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also fixes #14286 afaict.

@gkalpak
Copy link
Member

gkalpak commented Mar 2, 2018

Other than the CLA issue (and g3 sync), this is ready to go.

@ngbot
Copy link

ngbot bot commented Mar 20, 2018

Hi @smdunn! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

2 similar comments
@ngbot
Copy link

ngbot bot commented Mar 20, 2018

Hi @smdunn! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@ngbot
Copy link

ngbot bot commented Mar 20, 2018

Hi @smdunn! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@gkalpak gkalpak added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 21, 2018
@rkirov rkirov added cla: yes and removed cla: no labels Mar 21, 2018
@gkalpak gkalpak added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Mar 21, 2018
@gkalpak
Copy link
Member

gkalpak commented Mar 21, 2018

Seems like something went wrong. There are 141 commits on this PR now 😕

@gkalpak
Copy link
Member

gkalpak commented Mar 21, 2018

I fixed it up (and also renamed childComponentChangeDetector to viewChangeDetector, which is more accurate if I understand this comment correctly).

As soon as CI is green, I'll mark the PR for merge.
Thx again for working on this, @smdunn

@gkalpak gkalpak added cla: yes and removed cla: no labels Mar 21, 2018
@smdunn
Copy link
Author

smdunn commented Mar 21, 2018

Thanks for all the help with my first angular pull request @gkalpak

@gkalpak gkalpak added cla: yes and removed cla: no labels Mar 21, 2018
@ocombe ocombe added area: core Issues related to the framework runtime and removed area: core Issues related to the framework runtime labels Mar 22, 2018
@gkalpak gkalpak added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Mar 22, 2018
@ngbot
Copy link

ngbot bot commented Mar 22, 2018

I see that you just added the PR action: merge label, but the following checks are still failing:
    failure status "cla/google" is failing
    pending status "google3" is pending
    pending 1 pending code review

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

alxhub pushed a commit that referenced this pull request Apr 2, 2018
@alxhub
Copy link
Member

alxhub commented Apr 2, 2018

Author is a Googler, not sure why the CLA check is complaining.

@alxhub alxhub closed this in ad9ce5c Apr 2, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants